<?php

namespace App\Console\Tools\Clean;

use Illuminate\Console\Command;

class UserLoginLog extends Command
{
    /**
     * 命令名称及签名
     *
     * @var string
     */
    protected $signature = 'tools:clean:user-login-log {--days=60}';

    /**
     * 命令描述
     *
     * @var string
     */
    protected $description = '【工具】清理用户登录日志';

    /**
     * 创建命令
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 执行命令
     *
     * @return mixed
     */
    public function handle()
    {
        // 参数天数
        $days = $this->option('days');

        $timed = time() - 86400 * $days;

        // 输出提示【任务时间】
        $this->info($this->description . date('Y-m-d H:i:s', $timed));

        \App\Models\Agency\Auth\UserLoginLog::where('created', '<', $timed)->delete();
    }
}
